export default {
	dateTime(e) {
		let oldTime = new Date(e)
		let newTime = new Date()
		//传入的时间
		let d = oldTime.getTime()
		let h = oldTime.getHours()
		let m = oldTime.getMinutes()
		let Y = oldTime.getFullYear()
		let M = oldTime.getMonth()+1
		let D = oldTime.getDate()
		//当前时间
		let nd = newTime.getTime()
		let nh = newTime.getHours()
		let nm = newTime.getMinutes()
		let nY = newTime.getFullYear()
		let nM = newTime.getMonth()+1
		let nD = newTime.getDate()
		if (e === ""){
			return ""
		}
		//当天
		if (Y === nY && M === nM && D === nD) {
			if (h < 10) {
				h = '0' + h
			}
			if (m < 10) {
				m = '0' + m
			}
			return h + ':' + m
		}
		//昨天
		if (Y === nY && M === nM && D + 1 === nD) {
			return '昨天'
		}
		//前天
		if (Y === nY && M === nM && D + 2 === nD) {
			return '前天'
		} else {
			return Y + '/' + M + '/' + D
		}
	},
	
	birthDate(e) {
		let oldTime = new Date(e)
		//传入的时间
		let Y = oldTime.getFullYear()
		let M = oldTime.getMonth()+1
		let D = oldTime.getDate()
	
		//处理时间
		if(M<10) {
			M = '0'+M
		}
		if(D<10) {
			D = '0'+D
		}
		return Y + '-' + M + '-' + D
	},
	
	resgiterDate(e) {
		let oldTime = new Date(e)
		//传入的时间
		let d = oldTime.getTime()
		let h = oldTime.getHours()
		let m = oldTime.getMinutes()
		let Y = oldTime.getFullYear()
		let M = oldTime.getMonth()+1
		let D = oldTime.getDate()
	
		//处理时间
		if(M<10) {
			M = '0'+M
		}
		if(D<10) {
			D = '0'+D
		}
		if(h<10) {
			h = '0'+h
		}
		if(m<10) {
			m = '0'+m
		}
		return Y + '-' + M + '-' + D + ' ' + h + ':' + m
	},
	//使用时间创建文件夹
	fileName(e) {
		let oldTime = new Date(e)
		//传入的时间
		let Y = oldTime.getFullYear()
		let M = oldTime.getMonth()+1
		let D = oldTime.getDate()
	
		//处理时间
		if(M<10) {
			M = '0'+M
		}
		if(D<10) {
			D = '0'+D
		}
		return Y + M + D
	},
	//搜索延时
	debounce(fn,t){
		let delay = t||500
		let timer
		return function(){
			if(timer){
				clearTimeout(timer)
			}
			timer = setTimeout(()=>{
				timer = null
				fn.apply(this,arguments)
			},delay)
		}
	},
	//排列
	sortall: function(arr,obj,tip){
		if(tip === 0){
			//倒序
			for(let i=1;i<arr.length;i++){
				for(let j=i;j>0;j--){
					if(arr[j][obj]>arr[j-1][obj]){
						let s = arr[j]
						arr[j] = arr[j-1]
						arr[j-1] = s
					}
				}
			}
			return arr
		}else if(tip === 1){
			//升序
			for(let i=1;i<arr.length;i++){
				for(let j=i;j>0;j--){
					if(arr[j][obj]<arr[j-1][obj]){
						let s = arr[j]
						arr[j] = arr[j-1]
						arr[j-1] = s
					}
				}
			}
			return arr
		}
	}
}
